<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Profiling DocBook documents</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="article" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="d0e1"></a>Profiling DocBook documents</h1></div><div><h3 class="subtitle"><i>An easy way to personalize your content for several target audiences</i></h3></div><div><div class="author"><h3 class="author"><span class="firstname">Jirka</span> <span class="surname">Kosek</span></h3><div class="affiliation"><div class="address"><p>E-mail:&nbsp;<tt class="email">&lt;<a href="mailto:jirka@kosek.cz">jirka@kosek.cz</a>&gt;</tt><br>
<span class="otheraddr">Web:&nbsp;<a href="http://www.kosek.cz" target="_top">http://www.kosek.cz</a><br>
</span><br>
</p></div></div></div></div><div><p class="releaseinfo">
$Id: profiling.xml,v 1.3 2002/03/14 14:19:38 nwalsh Exp $
</p></div><div><p class="copyright">Copyright &copy; 2001 Ji&#345;&iacute; Kosek</p></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#d0e37">Introduction</a></span></dt><dt><span class="section"><a href="#d0e44">$0 solution</a></span></dt><dt><span class="section"><a href="#d0e85">Usage</a></span></dt><dt><span class="section"><a href="#d0e251">Single pass profiling</a></span></dt><dt><span class="section"><a href="#d0e277">Conclusion</a></span></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e37"></a>Introduction</h2></div></div></div><p>There are many situations when we need to generate several
versions of document with slightly different content from the single
source. User guide for program with both Windows and Linux port will
differ only in several topics related to installation and
configuration. It would be futile to create and maintain two different
documents in sync. Another real world example &#8211; in addition to
standard documentation we can have guide enriched with problem
solutions from help-desk. It also may be better to store these
information in one document in order to make them absolutely
synchronized.</p><p>Several high-end editing tools have built in support for
profiling. User can easily add target audiences for any part of
document in a simple to use dialog box. User can select desired target
audience before printing or generation of other output formats.
Software will automatically filter out excess parts of document and
pass rest of it to rendering engine. However, if your budget is
limited you can not use commercial solutions. In the following text I
will show you simple but flexible profiling solution based on freely
available technologies.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e44"></a>$0 solution</h2></div></div></div><p>In the document we mark parts targeted for particular platform
or user group. When generating final output version of document we
must do profiling i.e. personalization for particular target audience.
Only some parts of document are processed. DocBook has built in
support for marking document parts &#8211; on almost every element you
can use attributes like <tt class="sgmltag-attribute">os</tt>, <tt class="sgmltag-attribute">userlevel</tt> and <tt class="sgmltag-attribute">arch</tt>. We can store identifier of operating
system, user group or hardware architecture here. You can also store
profiling information into some general use attribute like <tt class="sgmltag-attribute">role</tt>. <a href="#ex.doc" title="Example&nbsp;1.&nbsp;Sample DocBook document with profiling information">Example&nbsp;1, &#8220;Sample DocBook document with profiling information&#8221;</a>
shows how document with profiling information might
look like.</p><div class="example"><a name="ex.doc"></a><p class="title"><b>Example&nbsp;1.&nbsp;Sample DocBook document with profiling information</b></p><pre class="programlisting">&lt;?xml version='1.0' encoding='iso-8859-1'?&gt;
&lt;!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.1.2//EN'
	                 'http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd'&gt;
&lt;chapter&gt;
&lt;title&gt;How to setup SGML catalogs&lt;/title&gt;

&lt;para&gt;Many existing SGML tools are able to map public identifiers to
files on your local file system. Mapping is specified in so called
catalog file. List of catalog files to use is stored in environment
variable &lt;envar&gt;SGML_CATALOG_FILES&lt;/envar&gt;.&lt;/para&gt;

&lt;para os="unix"&gt;On Unix systems you can set this variable by invoking
command &lt;command&gt;export SGML_CATALOG_FILES=/usr/lib/catalog&lt;/command&gt;
on command line. If you want maintain value of the variable between
sessions, place this command into startup file,
e.g. &lt;filename&gt;.profile&lt;/filename&gt;.&lt;/para&gt;

&lt;para os="win"&gt;In Windows NT/2000 you can set environment variable by
issuing command &lt;menuchoice&gt;&lt;guimenu&gt;Start&lt;/guimenu&gt;
&lt;guisubmenu&gt;Settings&lt;/guisubmenu&gt; &lt;guisubmenu&gt;Control
Pannel&lt;/guisubmenu&gt;
&lt;guimenuitem&gt;System&lt;/guimenuitem&gt;&lt;/menuchoice&gt;. Then select
&lt;guilabel&gt;Advanced&lt;/guilabel&gt; card in the dialog box and click on the
&lt;guibutton&gt;Environment Variables...&lt;/guibutton&gt; button. Using the
&lt;guibutton&gt;New&lt;/guibutton&gt; button you can add new environment variable
into your system.&lt;/para&gt;

&lt;/chapter&gt;</pre></div><p>DocBook documents are often processed by freely available DSSSL
and XSL stylesheets. Most DocBook users who want profiling starts with
creation of customization layer which filters out some parts of
document. This approach has several serious disadvantages. First, you
must create profiling customization for all output formats as they are
using different stylesheets. This mean that you must maintain same
code on several places or do some dirty tricks with importing several
stylesheets into one stylesheet.</p><p>Second drawback is more serious. If you override templates to
filter out documents, you can get almost correct output in a single
run of stylesheet. If you will closely look on generated output, you
will recognize that in the table of contents there are entries for
items which should be completely removed by profiling. Similar
problems are in several other places &#8211; e.g. skipped auto
generated numbers for tables, pictures and so on. To correct this one
should change all stylesheet code which generates ToC,
cross-references and so on to ignore filtered content. This is very
complicated task and will disallow you to easily upgrade to new
versions of stylesheets.</p><p>Thus we must use different approach. Profiling should be totally
separate step which will filter out some parts of original document
and will create new correct DocBook document. When processed with any
DocBook tool or stylesheet you will get always correct output from the
new standalone document now. Big advantage of this method is
compatibility with all DocBook tools. Filtered document is normal
DocBook document and it does not require any special processing. Of
course, there is also one disadvantage &#8211; formating is now two
stage process &#8211; first you must filter source document and in
second step you could apply normal stylesheets on result of filtering.
This may be little bit inconvenient for many users, but whole task can
be very easily automated by set of shell scripts or batch files or
whatever else. Starting from version 1.50 of XSL stylesheets you can
do profiling in one step together with normal stylesheet
processing.</p><div class="figure"><a name="d0e74"></a><p class="title"><b>Figure&nbsp;1.&nbsp;Profiling stream</b></p><div class="mediaobject"><img src="profile-chain.png" alt="Profiling stream"></div></div><p>When implementing filter, you can use many different approaches
and tools. I decided to use XSLT stylesheet. Writing necessary filter
is very easy in XSLT and many users have XSLT processor already
installed. Profiling stylesheet is part of standard XSL stylesheets
distribution and can be found in file
<tt class="filename">profiling/profile.xsl</tt>.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e85"></a>Usage</h2></div></div></div><p>If you want to generate Unix specific guide from our sample
document (<a href="#ex.doc" title="Example&nbsp;1.&nbsp;Sample DocBook document with profiling information">Example&nbsp;1, &#8220;Sample DocBook document with profiling information&#8221;</a>) you can do it in the following
way. (We assume, that command <span><b class="command">saxon</b></span> is able to run
XSLT processor on your machine. You can use your preffered XSLT
processor instead.)</p><pre class="screen"><span><b class="command">saxon</b></span> <tt class="option">-o</tt> unixsample.xml sample.xml profile.xsl "os=unix"</pre><p>We are processing source document
<tt class="filename">sample.xml</tt> with profiling stylesheet
<tt class="filename">profile.xsl</tt>. Result of transformation is stored
in file <tt class="filename">unixsample.xml</tt>. By setting parameter
<i class="parameter"><tt>os</tt></i> to value <tt class="literal">unix</tt>, we tell
that only general and Unix specific parts of document should be copied
to the result document. If you will look at generated result, you will
notice that this is correct DocBook document:</p><pre class="programlisting">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!DOCTYPE chapter
  PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
         "http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd"&gt;
&lt;chapter&gt;
&lt;title&gt;How to setup SGML catalogs&lt;/title&gt;

&lt;para&gt;Many existing SGML tools are able to map public identifiers to
files on your local file system. Mapping is specified in so called
catalog file. List of catalog files to use is stored in environment
variable &lt;envar&gt;SGML_CATALOG_FILES&lt;/envar&gt;.&lt;/para&gt;

&lt;para os="unix"&gt;On Unix systems you can set this variable by invoking
command &lt;command moreinfo="none"&gt;export SGML_CATALOG_FILES=/usr/lib/catalog&lt;/command&gt;
on command line. If you want maintain value of the variable between
sessions, place this command into startup file,
e.g. &lt;filename moreinfo="none"&gt;.profile&lt;/filename&gt;.&lt;/para&gt;

&lt;/chapter&gt;</pre><p>It is same as the input document, only Windows specific
paragraph is missing. Same procedure can be used to get Windows
specific version of document. The result generated by profiling
stylesheet have correct document type declaration (DOCTYPE). Without
it some tools would not be able to process them further. On the result
of filtering you can run common tools &#8211; for example DSSSL or XSL
stylesheets.</p><p>Stylesheet support several attributes for specifying profiling
values. They are summarized in the following list.</p><div class="variablelist"><dl><dt><span class="term"><i class="parameter"><tt>profile.os</tt></i></span></dt><dd><p>This parameter is used for specifying operating system (<tt class="sgmltag-attribute">os</tt> attribute) for which you want get
profiled version of document.</p></dd><dt><span class="term"><i class="parameter"><tt>profile.userlevel</tt></i></span></dt><dd><p>This parameter is used for specifying user level (<tt class="sgmltag-attribute">userlevel</tt> attribute) for which you want get
profiled version of document.</p></dd><dt><span class="term"><i class="parameter"><tt>profile.arch</tt></i></span></dt><dd><p>This parameter is used for specifying hardware architecture (<tt class="sgmltag-attribute">arch</tt> attribute) for which you want get
profiled version of document.</p></dd><dt><span class="term"><i class="parameter"><tt>profile.condition</tt></i>, </span><span class="term"><i class="parameter"><tt>profile.conformance</tt></i>, </span><span class="term"><i class="parameter"><tt>profile.revision</tt></i>, </span><span class="term"><i class="parameter"><tt>profile.revisionflag</tt></i>, </span><span class="term"><i class="parameter"><tt>profile.security</tt></i>, </span><span class="term"><i class="parameter"><tt>profile.vendor</tt></i>, </span><span class="term"><i class="parameter"><tt>profile.role</tt></i>, </span><span class="term"><i class="parameter"><tt>profile.lang</tt></i></span></dt><dd><p>These parameters can be used to specify target profile for
corresponding attributes.</p></dd><dt><span class="term"><i class="parameter"><tt>profile.attribute</tt></i></span></dt><dd><p>Name of attribute on which profiling should be based. It can be
used if profiling information is stored in other attributes then
<tt class="sgmltag-attribute">os</tt>, <tt class="sgmltag-attribute">userlevel</tt> and <tt class="sgmltag-attribute">arch</tt>.</p></dd><dt><span class="term"><i class="parameter"><tt>profile.value</tt></i></span></dt><dd><p>This parameter is used for specifying value for attribute
selected by <i class="parameter"><tt>attr</tt></i> parameter.</p><p>E.g. setting <tt class="literal">profile.attribute=os</tt> and
<tt class="literal">profile.value=unix</tt> is same as setting
<tt class="literal">os=unix</tt>.</p></dd><dt><span class="term"><i class="parameter"><tt>profile.separator</tt></i></span></dt><dd><p>Separator for multiple target audience identifiers. Default is
<tt class="literal">;</tt>.</p></dd></dl></div><p>Current implementation is able to handle multiple profiling
targets in one attribute. In that case you must separate identifiers
by semicolon:</p><pre class="programlisting">&lt;para os="unix;mac;win"&gt;...&lt;/para&gt;</pre><p>It is possible to use different separator than semicolon by
setting <i class="parameter"><tt>sep</tt></i> parameter. There cann't be spaces
between separator and target names.</p><p>You can also perform profiling based on several profiling
attributes in a single step as stylesheet can handle all parameters
simultaneously. For example to get hypothetical guide for Windows
beginners, you can run profiling like this:</p><pre class="screen"><span><b class="command">saxon</b></span> <tt class="option">-o</tt> xsample.xml sample.xml profile.xsl "profile.os=win" "profile.userlevel=beginner"</pre><p>As you can see above described profiling process can be used to
substitute SGML marked sections mechanism which is missing in XML.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e251"></a>Single pass profiling</h2></div></div></div><p>If you are using XSL stylesheets version 1.50 and later with
EXSLT enabled XSLT processor (Saxon, xsltproc, Xalan) you can do
profiling and transformation to HTML or FO in a single step. To do this
use stylesheet with prefix <tt class="filename">profile-</tt> instead of
normal one (e.g. <tt class="filename">profile-docbook.xsl</tt>,
<tt class="filename">profile-chunk.xsl</tt> or
<tt class="filename">profile-htmlhelp.xsl</tt>). For example to get HTML
version of profiled document use:</p><pre class="screen"><span><b class="command">saxon</b></span> <tt class="option">-o</tt> sample.html sample.xml .../html/profile-docbook.xsl "profile.os=win" "profile.userlevel=beginner"</pre><p>No additional processing is necessary. If you want to use
profiling with your customized stylesheets import profiling-able
stylesheet instead of normal one.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e277"></a>Conclusion</h2></div></div></div><p>Profiling is necessary in many larger DocBook applications. It
can be quite easily implemented by simple XSLT stylesheet which is
presented here. This mechanism can also be used to simulate behavior
of marked sections known from SGML.</p></div></div></body></html>